package com.feng.data
{
	import com.feng.model.EnmityRecord;
	import com.feng.model.Player;
	
	import flash.utils.Dictionary;

	/**
	 * 当前状态的数据
	 * @author 风之守望者
	 * 2013-3-27
	 */
	public class StateData
	{
		/** 我 */
		public var feng:Player;

		/** 敌人列表 */
		public var enemyList:Vector.<Player>;

		/** 玩家列表 */
		public var playerDic:Dictionary = new Dictionary();

		/** 活着的玩家数 */
		public var livingNum:int = 0;

		/** 平均玩家 */
		public var avgPlayer:Player = new Player({});

		/** 仇恨记录表格 */
		public var enmityRecordDic:Vector.<EnmityRecord> = new Vector.<EnmityRecord>();

		/** 我是否攻击两次 */
		public var isDouble:Boolean = false;

		/**
		 * 记住打我的人
		 */
		public var attackMeDic:Dictionary = new Dictionary();

		/** 我攻击了的玩家列表 */
		public var attackPlayerIdList:Array = [];
		
		/** 回合数 */
		public var turnIndex:int = 0;
		
		/** 玩家总攻击次数 */
		public var totalAttackNum:int;
		
		/** 出现最高攻击者次数 */
		public var hasMaxAttackNum:int;
		
		/** 攻击最高攻击者次数 */
		public var attackMaxAttackNum:int;
		
		/** 出现最高速度者次数 */
		public var hasMaxSpeedNum:int;
		
		/** 攻击最高速度次数 */
		public var attackMaxSpeedNum:int;
		
		public function StateData()
		{

		}

		/**
		 * 更新数据
		 * @param state
		 * @param myId
		 */
		public function updateData(state:Array, myId:int):void
		{
			enemyList = new Vector.<Player>();
			feng = null;

			livingNum = 0;
			var totalHP:Number = 0;
			var totalAttack:Number = 0;
			var totalSpeed:Number = 0;
			var totalDefense:Number = 0;

			avgPlayer.id = -1;
			avgPlayer.hp = 0;
			avgPlayer.attack = 0;
			avgPlayer.defense = 0;
			avgPlayer.speed = 0;

			var player:Player;
			var length:int = state.length;
			for (var i:int = 0; i < length; i++)
			{
				player = new Player(state[i]);
				playerDic[player.id] = player;
				//收集自己的数据
				if (player.id == myId)
				{
					feng = player;
				}
				//收集还活着的敌人玩家
				else if (player.isDie == false)
				{
					enemyList.push(player);
				}

				if (player.isDie == false)
				{
					livingNum++;
					totalHP += player.hp;
					totalAttack += player.attack;
					totalDefense += player.defense;
					totalSpeed += player.speed;
				}
			}
			if (livingNum > 0)
			{
				avgPlayer.hp = totalHP / livingNum;
				avgPlayer.attack = totalAttack / livingNum;
				avgPlayer.defense = totalDefense / livingNum;
				avgPlayer.speed = totalSpeed / livingNum;
			}

		}
	}
}
